<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use PhpParser\Node\Stmt\Foreach_;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string|null
     */
    protected function redirectTo($request)
    {

        if (!$request->expectsJson()) {
            if (strpos($request->header('User-Agent'), "DingTalk") !== false) {
                foreach (app("DT")->config->app_url as $v) {
                    if ($v['name'] == '免登授权码跳转地址') {
                        return $v['url'];
                    }
                }
            } else
                return route('login');
        }
    }
}
